//
//  SDFocusDoctorController.m
//  SuperDoctor
//
//  Created by 李忠 on 7/5/16.
//  Copyright © 2016 SD. All rights reserved.
//
/** 获取关注医生列表接口 */

#import "SDFocusDoctorController.h"
#import "SDNetWorkTool.h"
#import "SDFocusModel.h"
#import "SDTableViewCell.h"
#import "SDInfoController.h"

@interface SDFocusDoctorController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) NSArray * dataArray;

@property (nonatomic,strong) UITableView * focusTable;

@end

static NSString * identifier = @"identifier";

@implementation SDFocusDoctorController


// tableView 懒加载

-(UITableView *)focusTable{
    
    if (_focusTable == nil) {
        
        _focusTable = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStyleGrouped];
        _focusTable.delegate = self;
        _focusTable.dataSource = self;
        [self.view addSubview:_focusTable];
        _focusTable.sectionFooterHeight = 0;
        _focusTable.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _focusTable;
}

// 获取数据
-(void)setDataArray:(NSArray *)dataArray{
    
    _dataArray = dataArray;
    
    [self.focusTable reloadData];
}

- (void)viewDidLoad {
    [super viewDidLoad];
   
    [self getData];
    [self setTableView];

}

// 设置 tabeView 约束

-(void)setTableView{

    [self.focusTable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.equalTo(self.view).with.insets(UIEdgeInsetsMake(0, 0, 0, 0));
    }];
    
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return self.dataArray.count;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SDTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    
    SDFocusModel * model = self.dataArray[indexPath.section];
    
    if (cell == nil) {
        
        cell = [[SDTableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    
    cell.model = model;
    
    return cell;
    
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    SDFocusModel * model = self.dataArray[indexPath.section];
    
    SDInfoController * vc = [[SDInfoController alloc]init];
    
    vc.navigationItem.title = @"医生基本信息";
    
    vc.model = model;
    
    [self jumpOtherViewController:vc];
}
#pragma mark 获取数据

-(void)getData{
    
    [SDFocusModel getModelWithlock:^(NSArray *dataArray) {
        
        self.dataArray = dataArray;
        
    } error:^{
        
    }];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 15;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 100;
}

@end
